package com.ruoyi.system.wnjk.test.rabbitmq.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.ruoyi.system.wnjk.test.rabbitmq.RabbitMQInfo;

public class RabbitMqUtils {
    // 获得RabbitMQ连接的channel
    public static Channel getChannel() throws Exception {
        // 创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(RabbitMQInfo.Info.HOST);
        factory.setPort(RabbitMQInfo.Info.PORT);
        factory.setUsername(RabbitMQInfo.Info.USER_NAME);
        factory.setPassword(RabbitMQInfo.Info.PASS_WORD);
        // 创建一个connection
        Connection connection = factory.newConnection();
        // 创建一个channel
        Channel channel = connection.createChannel();
        return channel;
    }
}
